public class Homework {
    //有三个线程，线程名称分别为：a，b，c。
    //每个线程打印自己的名称。
    //需要让他们同时启动，并按 c，b，a的顺序打印
    public static void main(String[] args) throws InterruptedException {
        //使用3个锁,然后利用 wait 和 notify 进行解除等待操作
        Object locker1 = new Object();
        Object locker2 = new Object();
        Object locker3 = new Object();

        Thread a = new Thread(()->{
           synchronized (locker1){
               try {
                   locker1.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("a");
           }
        });

        Thread b = new Thread(()->{
            synchronized (locker2){
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("b");
            }
        });

        Thread c = new Thread(()->{
            synchronized (locker3){
                try {
                    locker3.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("c");
            }
        });

        //解除等待
        Thread a1 = new Thread(()->{
           synchronized (locker1){
               locker1.notify();
           }
        });

        Thread b1 = new Thread(()->{
            synchronized (locker2){
                locker2.notify();
            }
        });

        Thread c1 = new Thread(()->{
            synchronized (locker3){
                locker3.notify();
            }
        });

        a.start();
        b.start();
        c.start();
        Thread.sleep(100);//全部进入等待
        c1.start();
        Thread.sleep(100);//此时保证c已被释放
        b1.start();
        Thread.sleep(100);//此时保证b已经被释放
        a1.start();
    }
}
